import { reactive } from 'vue';
import { EnumDataType } from '@/config/config';
import { dataType, supplyZero } from '@/utils/tools';

interface Itime {
    year: string,  
    month: string,
    day: string,
    hour: string,
    minute: string,
    second: string,
    week: string
} 

const time = reactive<Itime>({
    year: '2024',
    month: '01',
    day: '01',
    hour: '00',
    minute: '00',
    second: '00',
    week: ''
});

// 星期
const Weeks = [ '星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六' ];

function setTime(date = new Date()) {
    if( dataType(date) !== EnumDataType.date) return;

    time.year = date.getFullYear().toString();
    time.month = supplyZero( date.getMonth() + 1 );
    time.day = supplyZero( date.getDate() );
    time.hour = supplyZero( date.getHours() );
    time.minute = supplyZero( date.getMinutes() );
    time.second = supplyZero( date.getSeconds() );
    time.week = Weeks[date.getDay()];
    //  获取当前的时间
}

export default function useTime(): [ Itime, any ] {
    return [ time, setTime ];
}